
def biber_i_dolik(a):
        for i in range(2, int(a**0.5)+1):
            if a % i == 0:
                return False
                break
        return True

bebr = list(input().split(" "))
#print(*bebr)
zov = ["zero" ,"one", "two", "three" ,"four", "five", "six ","seven" ,"eight" ,"nine"]
g = 0
cache = 0
num = 0
iseror = False
for b in bebr:
    g+=1
    if b not in zov or len(bebr) != 3:
        print("Wrong input")
        iseror = True
        break
    elif b == zov[0]:
        cache = 0
    elif b == zov[1]:
        cache = 1
    elif b == zov[2]:
        cache = 2
    elif b == zov[3]:
        cache = 3
    elif b == zov[4]:
        cache = 4
    elif b == zov[5]:
        cache = 5
    elif b == zov[6]:
        cache = 6
    elif b == zov[7]:
        cache = 7
    elif b == zov[8]:
        cache = 8
    elif b == zov[9]:
        cache = 9
    if g == 1:
        num += cache*100
    elif g == 2:
        num += cache * 10
    elif g == 3:
        num += cache
if iseror == False:
    print(num)
    g = 0
    d1 = 0
    d2 = 0
    while True:
        if biber_i_dolik(num+g):
            d1 = num+g
        if biber_i_dolik(num-g):
            d2 = num-g
        if d1 != 0 and d2 != 0:
            if d1-num > num-d2:
                print(d2)
                break
            else:
                print(d1)
                break
        g+=1





    



